package com.situ.study.controller;

import com.situ.study.pojo.User;
import com.situ.study.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.w3c.dom.stylesheets.LinkStyle;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IUserService userService;

    // /user/selectAll
    /*@RequestMapping("/selectAll")
    @ResponseBody   // 以json返回数据
    public List<User> selectAll() {
        *//*List<User> list = new ArrayList<>();
        User user1 = new User(1, "zhangsan111", "123", 23);
        User user2 = new User(2, "zhangsan222", "123", 23);
        User user3 = new User(3, "zhangsan3333", "123", 23);
        list.add(user1);
        list.add(user2);
        list.add(user3);*//*

        List<User> list = userService.selectAll();

        return list;
    }*/

    @RequestMapping("/selectAll")
    public String selectAll(Model model) {
        List<User> list = userService.selectAll();
        model.addAttribute("list", list);
        return "/WEB-INF/user_list.jsp";
    }
}
